﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using Sebarf.Core.Interfaces;
using Sebarf.Services.Interfaces;
using Sebarf.Session.Interfaces;

#endregion

namespace Sebarf.Server {
	/// <summary>
	/// Description of the class
	/// </summary>
	public class UserSessionHandlerService : Service, IUserSessionHandlerService {
		#region Public Properties

		public WcfBasedServer WcfBasedServer { get; set; }

		[ServiceRequest]
		public IDiagnosticsServiceLocatorService DiagnosticsServiceLocatorService { get; set; }

		public string SessionId { get; set; }

		#endregion

		#region Public Methods

		public UserSessionHandlerService(WcfBasedServer server, string sessionId) {
			WcfBasedServer = server;
			SessionId = sessionId;
		}

		#endregion

		#region IUserSessionHandlerService Members

		public void RemoveSession() {
			// get handling engine
			IRequestHandlerEngine engine = WcfBasedServer.EnginesByCaller[SessionId];

			// deregister engine
			WcfBasedServer.EnginesByCaller.Remove(SessionId);

			// shutdown services
			foreach (IServiceImpl service in DiagnosticsServiceLocatorService.GetAllRegisteredServices<IServiceImpl>()) {
				service.DoShutdown();
			}
			// shutdown engine
			(engine as IRequestHandlerEngineImpl).Dispose();
		}

		#endregion
	}
}